package belf.migrate.engine.ddl.function;

import belf.migrate.api.common.DatabaseIdentifier;
import belf.migrate.api.model.QualifiersModel;
import belf.migrate.api.table.schema.Catalog;
import belf.migrate.engine.ddl.AbstractConvertFactory;
import belf.migrate.engine.ddl.BaseDDLConvert;
import belf.migrate.engine.ddl.function.mysql.MySql2DMFunctionConvert;
import belf.migrate.engine.ddl.function.oracle.Oracle2DMFunctionConvert;
import belf.migrate.engine.ddl.function.oracle.Oracle2KingbaseFunctionConvert;

public class FunctionConvertFactory extends AbstractConvertFactory {
    @Override
    public BaseDDLConvert create(String schema,
                                 String objectName,
                                 String sql,
                                 Catalog sourceCatalog,
                                 Catalog sinkCatalog,
                                 QualifiersModel qualifiersModel) {
        String IDENTIFIER = sourceCatalog.name() + "-" + sinkCatalog.name();
        switch (IDENTIFIER) {
            case DatabaseIdentifier.ORACLE + "-" + DatabaseIdentifier.DAMENG:
                return new Oracle2DMFunctionConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
            case DatabaseIdentifier.ORACLE + "-" + DatabaseIdentifier.KINGBASE:
                return new Oracle2KingbaseFunctionConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
            case DatabaseIdentifier.MYSQL + "-" + DatabaseIdentifier.DAMENG:
                return new MySql2DMFunctionConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
            case DatabaseIdentifier.MYSQL + "-" + DatabaseIdentifier.KINGBASE:
                return new MySql2DMFunctionConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
            default:
                return new BaseDDLConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
        }
    }
}
